package BIO.test04;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class HandlerSocketServerPool {
    //1.创建一个线程池的成员变量，用于存储线程池对象
    private ExecutorService executorService;

    /**
     * 2.创建这个类的对象的时候初始化线程池对象
     */
    public HandlerSocketServerPool(int coreSize,int maxSize,int queueSize){
        executorService = new ThreadPoolExecutor(coreSize,maxSize,120,
                TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(queueSize)); //有界队列
    }

    /**
     * 3.提供一个方法提交任务给线程池的任务队列来暂存，等着线程池处理
     */
    public void execute(Runnable target){
        executorService.execute(target);
    }

}
